package lxn;

//import static org.junit.Assert.assertTrue;
import robocode.RoundEndedEvent;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests if Obon will forego changing heading when struck by a bullet at specific energy levels.
 * Currently test is incomplete and always fail. Critical statements have been commented out.
 * 
 * @author Leonardo Nguyen
 * @version Java 1.6.0_21
 */
public class TestObonInNoDodgeMode extends RobotTestBed {
  
  // Assumes starting energy of Obon is 100.
  private double previousObonEnergy = 100.0;
  //private double previousBearing;
  //private double currentBearing;
  // True when Obon has been struck by a bullet.
  private boolean hasBeenHitByBullet = false;
  
  
  // True if Obon is struck by a bullet and still has 90 or greater energy.
  //private boolean obonInNoDodgeMode = false;
  // True if Obon does not change heading after being struck by a bullet.
  //private boolean obonDidNotDodge = false;
  
  
  
  // Track the current turn of the round.
  private int turnCount = 0;
  // The turn to evaluate if Obon has changed headings after being struck by a bullet.
  //private int evaluateObonStateTurn = 0;
  
  /**
   * Specifies that SittingDuck and Obon are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override public String getRobotNames() {
    return "sample.Tracker,lxn.Obon";
  }
  
  /**
   * At the end of each turn, check to see if Obon has been struck by a bullet and if at 90 or
   * greater energy, will evaluate Obon's heading 8 turns thereafter to determine if it foregone
   * changing of heading.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override public void onTurnEnded (TurnEndedEvent event) {
    
    turnCount++;
    IRobotSnapshot obon = event.getTurnSnapshot().getRobots()[1];
    double currentObonEnergy = obon.getEnergy();
    
    if (!hasBeenHitByBullet && ((currentObonEnergy - previousObonEnergy) <= -10)) {
      hasBeenHitByBullet = true;
      //previousBearing = obon.getBodyHeading();
    }
    
    //if (hasBeenHitByBullet && currentObonEnergy > 90) {
      //obonInNoDodgeMode = true;
      //evaluateObonStateTurn = turnCount + 8;
    //}
    
    //if (hasBeenHitByBullet && evaluateObonStateTurn == turnCount) {
      //currentBearing = obon.getBodyHeading();
      //if (currentBearing == previousBearing) {
        //obonDidNotDodge = true;
      //}
    //}
    
    previousObonEnergy = currentObonEnergy;
  }
  
  /**
   * Resets all counters.
   * 
   * @param event Details about the completed round. 
   */
  public void onRoundEnded(RoundEndedEvent event) {
    
    turnCount = 0;
    //evaluateObonStateTurn = 0;
    
  }
  
  /**
   * This test runs for 50 rounds.
   * 
   * @return The number of rounds. 
   */
  @Override public int getNumRounds() {
    return 50;
  }
  
  /**
   * After running all the rounds, checks to see if Obon has foregone changing bearing to emulate
   * the state of no dodging.
   * 
   * @param event Details about the completed battle.
   */
  @Override public void onBattleCompleted(BattleCompletedEvent event) {
    
    // Currently test always fails.
    //assertTrue("Obon has foregone dodging due to high energy levels", obonDidNotDodge);
  }
}
